<?php

class Eleven_Form_Picture_Upload extends Zend_Form 
{ 
    public function init()
    {
        $this->addElementPrefixPath(
            'Eleven_Validate',
            APPLICATION_PATH . '/models/validate/',
            'validate'
        );
        
        $this->setDisableLoadDefaultDecorators(true);
        $this->setDecorators(array(
            array(
                'ViewScript',
                array('viewScript'=>'picture/_upload.phtml')
            ),
            'Form'
        ));
        
        $this->setName('upload');
        $this->setAttrib('enctype', 'multipart/form-data');
        
        $this->addElement('select','cate', array(
            'required' => true,
		    'label'		=> '内容分类：',
		    'validators' => array(array('TopicValidate')),
        ));
        
		$topicMultiOptions = array();
        $topicMultiOptions[0] = '';
        
        $_pictureModel = new Eleven_Model_Picture();
        foreach($_pictureModel->getCatepics() as $cate)
        {
            $topicMultiOptions[$cate->id] = $cate->title;
        }                
        $this->getElement('cate')->setMultiOptions($topicMultiOptions);
        $this->getElement('cate')->setValue('0');
        $this->getElement('cate')->setDecorators(array(
            'ViewHelper',
		    'Errors',
        ));
        
        $desc1 = new Zend_Form_Element_Text('desc1');
        $desc1->addValidator('NotEmpty');
        $desc1->setDecorators(array(
            'ViewHelper',
        ));
        $desc1->setAttrib('class', 'pic_desc');
                
        $file1 = new Zend_Form_Element_File('pic1');
        $file1->setDestination('./data/uploads/tmp')
            ->addPrefixPath('Eleven_Validate',APPLICATION_PATH . '/models/validate/','validate')
            ->addValidator('Count', false, 1)
            ->addValidator('Size', false, 1024000)
            ->addValidator('CFExtension', false, 'jpg,png,gif');
        $file1->removeDecorator('Label');
        $file1->removeDecorator('HtmlTag');
        $file1->setAttribs(array('class'=>'pic_file', 'size'=>'43'));
        
        $desc2 = new Zend_Form_Element_Text('desc2');
        $desc2->addValidator('NotEmpty');
        $desc2->setDecorators(array(
            'ViewHelper',
        ));
        $desc2->setAttrib('class', 'pic_desc');
        
        $file2 = new Zend_Form_Element_File('pic2');
        $file2->setDestination('./data/uploads/tmp')
            ->addPrefixPath('Eleven_Validate',APPLICATION_PATH . '/models/validate/','validate')
            ->addValidator('Count', false, 1)
            ->addValidator('Size', false, 1024000)
            ->addValidator('CFExtension', false, 'jpg,png,gif');
        $file2->removeDecorator('Label');
        $file2->removeDecorator('HtmlTag');
        $file2->setAttribs(array('class'=>'pic_file', 'size'=>'43'));
        
        $desc3 = new Zend_Form_Element_Text('desc3');
        $desc3->addValidator('NotEmpty');
        $desc3->setDecorators(array(
            'ViewHelper',
        ));
        $desc3->setAttrib('class', 'pic_desc');
        
        $file3 = new Zend_Form_Element_File('pic3');
        $file3->setDestination('./data/uploads/tmp')
            ->addPrefixPath('Eleven_Validate',APPLICATION_PATH . '/models/validate/','validate')
            ->addValidator('Count', false, 1)
            ->addValidator('Size', false, 1024000)
            ->addValidator('CFExtension', false, 'jpg,png,gif');
        $file3->removeDecorator('Label');
        $file3->removeDecorator('HtmlTag');
        $file3->setAttribs(array('class'=>'pic_file', 'size'=>'43'));
        
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('')
                ->setAttrib('class','pic_submit');
        
        $this->addElements(array($desc1, $desc2, $desc3, $file1, $file2, $file3, $submit));
    } 
} 
